#include "stdafx.h"
#include "savelist.h"

CLock::CLock(HANDLE hMutex)
{
	m_hMutex = hMutex;
	WaitForSingleObject(m_hMutex, INFINITE);
}

CLock::~CLock()
{
	ReleaseMutex(m_hMutex);
}

CPlayList::CPlayList()
{
	hMutex = CreateMutex(NULL, false, NULL);
	m_packcount = 0;
}

CPlayList::~CPlayList()
{
	CloseHandle(hMutex);
}

char* CPlayList::pack_front()
{
	return m_package.front();
}

char* CPlayList::pack_pop()
{
	CLock clock(hMutex);
	char *p = 0;
	p = m_package.front();
	m_package.pop_front();
	m_packcount--;
	return p;
}

int CPlayList::getPackSize()
{
	CLock clock(hMutex);
	return m_packcount;
}

void CPlayList::pack_push(char *p)
{
	CLock clock(hMutex);
	m_package.push_back(p);
	m_packcount++;
}